package com.shopManager.utils;


import com.shopRedis.feign.RedisFeign;
import com.shopRedis.feign.factory.RedisFeignFactory;
import feign.*;
import feign.auth.BasicAuthRequestInterceptor;
import feign.codec.Decoder;
import feign.codec.Encoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

@Import(FeignClientsConfiguration.class)
@Component
public class RedisCacheUtils {


    RedisFeign redisFeign;
    @Value("${redis-service}")
    String service;
    Decoder decoder;
    Encoder encoder;
    Client client;
    Contract contract;

    public String getService() {
        return service;
    }

    public RedisFeign getRedisFeign() {
        synchronized (this){
            if(redisFeign==null){
                this.redisFeign = Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract).target(RedisFeign.class,"http://"+service+"/");
            }
        }
        return redisFeign;
    }

    public RedisCacheUtils(Decoder decoder, Encoder encoder, Client client, Contract contract) {
        this.decoder=decoder;
        this.encoder=encoder;
        this.client=client;
        this.contract=contract;
    }
}
